package com.objcat.servicea.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.objcat.servicea.entity.po.PowerPo;
import com.objcat.servicea.entity.po.RolePo;
import com.objcat.servicea.entity.po.RolePowerPo;
import com.objcat.servicea.entity.vo.UserVo;
import com.objcat.servicea.mapper.PowerMapper;
import com.objcat.servicea.service.PowerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.objcat.servicea.service.RolePowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author misheep
 * @since 2020-07-27
 */
@Service
public class PowerServiceImpl extends ServiceImpl<PowerMapper, PowerPo> implements PowerService {

    @Autowired
    private RolePowerService rolePowerService;
    @Autowired
    private PowerMapper powerMapper;

    /**
     * 获取权限
     * @param rolePo
     * @return
     */
    @Override
    public List<PowerPo> getPower(RolePo rolePo) {
        List<RolePowerPo> rolePowerPoList = rolePowerService.getRolePower(rolePo);
        QueryWrapper<PowerPo> queryWrapper = new QueryWrapper<>();
        rolePowerPoList.forEach(rolePowerPo -> {
            queryWrapper.eq("power_id", rolePowerPo.getPowerId());
        });
        return powerMapper.selectList(queryWrapper);
    }

    @Override
    public boolean checkPower(UserVo userVo) {
        return false;
    }
}
